package com.wzs.repository.impl;

import com.wzs.bean.UserLoginLog;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class LogRepository{

    @Autowired
    private SessionFactory sessionFactory;

    private Session getCurrentSession() {
        return this.sessionFactory.openSession();
    }

    public List<UserLoginLog> ListByUserId(Integer uid){
        List<UserLoginLog> list = null;
        Criteria criteria = getCurrentSession().createCriteria(UserLoginLog.class);
        Criterion userId = Restrictions.eq("userId", uid);
        criteria.add(userId);
        list = criteria.list();
        return list;
    }

    public Integer save(UserLoginLog entity) {
        Integer save = (Integer)getCurrentSession().save(entity);
        return save;
    }

}
